#include <vcl.h>
#pragma hdrstop
#pragma package(smart_init)
#include "Pen.h"

//Non-clock direction, and using grades instead of radians.
Pen::Pen( float x , float y , float z , float d ){
   position = new VectorPoint3D( x , y , z );
   direction = d;
}

Pen::~Pen(){
        delete position;
}


void Pen::lineTo( VectorPoint3D* point ) {
        glBegin(GL_LINES);
                glVertex2f( position->getX( ) , position->getY( ) );
                glVertex2f( point->getX( ) , point->getY( ) );
        glEnd();
        position->setX(point->getX());
        position->setY(point->getY());

}


void Pen::moveTo( VectorPoint3D* point ){
        position->setX( point->getX( ) );
        position->setY( point->getY( ) );
}

void Pen::moveToRel( float incx , float incy ) {
        glBegin( GL_LINES );
                glVertex2f( position->getX( ) , position->getY( ) );
                position->setX( position->getX( )+ incx );
                position->setY( position->getY( )+ incy );
                glVertex2f( position->getX( ) , position->getY( ) );
        glEnd( );
}

void Pen::turnTo( float angle ) {
        direction = angle;
        while ( direction >= 360.0 || direction < 0.0 ) {
                if (direction >0.0) {
                        direction -= 360.0;
                } else {
                        direction += 360.0;
                }
        }
}

void Pen::turn( float angle ) {
        direction = direction + angle;
        while ( direction >= 360.0 || direction < 0.0) {
                if (direction >0.0) {
                         direction -= 360.0;
                } else {
                        direction += 360.0;
                }
        }
}

void Pen::goTo( float distance , bool cont ) {
        float rad=(PI*direction)/180.0;
        if ( cont ) {
                glBegin(GL_LINES);
                        glVertex2f( position->getX( ) , position->getY( ) );
                        position->setX( position->getX( ) + ( distance* cos( rad ) ) );
                        position->setY( position->getY( ) + ( distance* sin( rad ) ) );
                        glVertex2f( position->getX( ) , position->getY( ) ) ;
                glEnd( );
        } else {
                position->setX( position->getX( )+ (distance* cos( rad )));
                position->setY( position->getY( )+ (distance* sin( rad )));
     }
}


float Pen::getDirection( ) {
        return direction;
}

VectorPoint3D* Pen::getPosition( ) {
        return position;
}


